from sympy import symbols, Eq, solve


class EquationSolver:
    """基于sympy的方程求解器（支持高精度，显式处理实数变量）"""

    @staticmethod
    def solve_equation(equation):
        """求解方程"""
        try:
            # 分离方程左右两边
            left, right = equation.split('=')
            x = symbols('x')
            eq = Eq(eval(left.replace('x', 'x')), eval(right.replace('x', 'x')))
            solutions = solve(eq, x)
            # 直接返回原始解，不转换为浮点数
            return [str(sol) for sol in solutions]
        except Exception as e:
            print(f"解方程错误: {e}")
            return []
